import QtQuick 2.4
import Qt.labs.controls 1.0
import QtQuick.Layouts 1.1
import QtQuick.XmlListModel 2.0
import "../template" as Tm
import "../js/TestManagerNavigator.qml.js" as Jit
Tm.Navigator {
    id: nav
    title: "测试内容"
    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 9

        ListView{
            id:listView
            Layout.fillWidth: true
            Layout.fillHeight: true
            model: XmlListModel {
                id: xmlModel
                source: http.build("/test.xml?t=s", {uid:usinfo.id})
                query: "/tests/test"

                XmlRole { name: "id"; query: "id/string()" }

                XmlRole { name: "content"; query: "content/string()" }
            }

            delegate: ItemDelegate {
                id: delegate
                width: listView.width

                text: content
                onClicked: {input.text = content;
                    mwindow.itemid = id; listView.currentIndex = index;  mwindow.open()}
            }
        }
        Tm.MenuWindow {
            id: mwindow
            onEditTriggered: Jit.edit()
            onDelTriggered: Jit.del()
        }

//        TestPopupNavigator {
//            id: testPop
//            property bool editable: false
//            onOkTriggered: editable ? Jit.editcommit() : Jit.addcommit()
//        }

        Tm.InputView{id: input
            title: "测试内容"
            property bool editable: false
            onClicked: editable ? Jit.editcommit() : Jit.addcommit()
            label: "名称"
        }

        Button {
            Layout.alignment: Qt.AlignHCenter
            Layout.preferredWidth: implicitWidth * 2
            text: "添加测试内容"
            onClicked: {input.editable = false; input.text = ""; input.open()}
        }
    }
}
